define(["jquery", "easy-admin"], function ($, ea) {
 
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'management.lease/index',
        add_url: 'management.lease/add',
        edit_url: 'management.lease/edit',
        delete_url: 'management.lease/delete',
        export_url: 'management.lease/export',
        modify_url: 'management.lease/modify',
        price_url: 'management.lease/price',
       
    };
 $('.submit').click(function(){
        // var content=CKEDITOR.instances.describe.getData();//entity_content为textarea的ID
        // $('.describe').val(content)
        let is_submit = 1
        // 验证必填
        let ver  = $('input')
        ver.each(function(i){
            let that = ver[i]
            let verify = $(that).attr('lay-verify')
            if (verify == 'required') {
                if(!$(that).val()){
                    let placeholder = $(that).prop('placeholder')
                    layer.msg(placeholder)
                    is_submit = 0
                    return false
                }
            }
        })
        if(!is_submit){
            return false
        }
        ea.request.post({
            url:$(this).attr('data-url'),
            data:$('form').serializeArray()
        }, function (res) {
            ea.msg.success(res.msg, function () {
               
                window.parent.location.reload();
            });
        });
    })

    $('form').submit(function(){
        return false
    })
    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar:['refresh',  [{
                    text: '添加',
                    url: init.add_url,
                    method: 'open',
                    auth: 'add',
                    class: 'layui-btn layui-btn-normal layui-btn-sm',
                    icon: 'fa fa-plus ',
                    extend: 'data-full="true"',
                }],],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id'},
                    {field: 'title', title: '名称',search:false},
                 
                    {width: 250, title: '操作', templet: ea.table.tool,
                    operat: [
                        [{
                            text: '编辑',
                            field:'id',
                            url: init.edit_url,
                            method: 'open',
                            auth: 'edit',
                            class: 'layui-btn layui-btn-success layui-btn-xs',
                            extend: 'data-full="true"',
                        },
                        {
                            title:'确定删除？',
                            text: '删除',
                            field:'id',
                            url: init.delete_url,
                            method: 'delete',
                            class: 'layui-btn layui-btn-danger layui-btn-xs',
                        },
                    ]
                ]
                    },
                ]],
            });

            ea.listen();
        },
  
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        price: function () {
            ea.listen();
        },
    };
    return Controller;
});